package com.xiaoxi.bms.domain.password.check;

import com.xiaoxi.bms.domain.password.CheckResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @ClassName ContainDigitCheck
 * @Description
 * @Author xiaoxi
 * @Date 2022/7/11 21:33
 * @Version 1.0
 */
@Component
public class ContainDigitCheck implements IPasswordCheck {

    @Value("${bms.password-check.check-digit}")
    private boolean checkDigit;

    public CheckResult check(String password, CheckResult checkResult) {

        if (this.checkDigit) {

            char[] chPass = password.toCharArray();
            boolean flag = false;
            int numCount = 0;

            for (char pass : chPass) {
                if (Character.isDigit(pass)) {
                    ++numCount;
                }
            }

            if (numCount >= 1) {
                flag = true;
            }

            if (!flag) {
                checkResult.getConfirmInfo().add("数字");
            } else {
                checkResult.setConfirmCount(checkResult.getConfirmCount() + 1);
            }

        }
        return checkResult;
    }
}
